//
//  ReservationFlowConfig.swift
//  CMB250716
//
//  Created by Trae AI on 2024/12/19.
//  Copyright © 2024 CuMrBull. All rights reserved.
//

import SwiftUI

/// 预订流程配置 - 紧凑单页面设计
struct ReservationFlowConfig {
    
    // MARK: - 布局配置
    struct Layout {
        // 间距
        static let horizontalPadding: CGFloat = 20
        static let verticalPadding: CGFloat = 16
        static let sectionSpacing: CGFloat = 24
        static let itemSpacing: CGFloat = 12
        static let cardItemSpacing: CGFloat = 8
        static let gridSpacing: CGFloat = 12
        static let scrollPadding: CGFloat = 4
        
        // 卡片
        static let cardPadding: CGFloat = 16
        static let cardCornerRadius: CGFloat = 16
        
        // 订单类型卡片
        static let orderTypeCardHeight: CGFloat = 100
        
        // 座位类型卡片
        static let seatingCardHeight: CGFloat = 80
        
        // 时间选择
        static let timeSlotWidth: CGFloat = 80
        static let timeSlotHeight: CGFloat = 60
        
        // 按钮
        static let buttonHeight: CGFloat = 50
        static let buttonCornerRadius: CGFloat = 25
        static let numberButtonSize: CGFloat = 44
        
        // 图标
        static let iconSize: CGFloat = 24
    }
    
    // MARK: - 字体配置
    struct Typography {
        static let sectionTitleFont: Font = .headline
        static let cardTitleFont: Font = .subheadline
        static let bodyFont: Font = .body
        static let captionFont: Font = .caption
        static let buttonFont: Font = .headline
        static let valueFont: Font = .subheadline
        static let numberFont: Font = .title3
        static let timeFont: Font = .subheadline
        static let iconFont: Font = .title2
    }
    
    // MARK: - 动画配置
    struct Animation {
        static let selectionDuration: Double = 0.3
        static let springResponse: Double = 0.3
        static let springDamping: Double = 0.7
    }
    
    // MARK: - 颜色配置
    struct Colors {
        static let primaryOrange = Color.orange
        static let primaryGreen = Color.green
        static let primaryBlue = Color.blue
        static let primaryPurple = Color.purple
        
        static let backgroundPrimary = Color.black.opacity(0.4)
        static let backgroundSecondary = Color.black.opacity(0.2)
        static let borderPrimary = Color.white.opacity(0.1)
        static let borderSecondary = Color.orange.opacity(0.8)
        
        static let textPrimary = Color.white
        static let textSecondary = Color.gray
        static let textAccent = Color.orange
    }
    
    // MARK: - 本地化配置
    struct Localization {
        // 主要标题
        static let selectOrderType_zh = "选择订单类型"
        static let selectOrderType_en = "Select Order Type"
        
        // 人数选择
        static let partySize_zh = "用餐人数"
        static let partySize_en = "Party Size"
        static let people_zh = "人"
        static let people_en = "People"
        
        // 座位类型
        static let seatingType_zh = "座位类型"
        static let seatingType_en = "Seating Type"
        static let availableSeats_zh = "空余"
        static let availableSeats_en = "Available"
        
        // 日期时间
        static let selectDate_zh = "选择日期"
        static let selectDate_en = "Select Date"
        static let selectTime_zh = "选择时间"
        static let selectTime_en = "Select Time"
        static let noAvailableTime_zh = "暂无可预订时间\n请选择其他日期或联系餐厅"
        static let noAvailableTime_en = "No available time slots\nPlease select another date or contact restaurant"
        
        // 按钮
        static let confirmReservation_zh = "确认预订"
        static let confirmReservation_en = "Confirm Reservation"
        static let cancel_zh = "取消"
        static let cancel_en = "Cancel"
        
        // 免责声明
        static let disclaimer_zh = "预订须知"
        static let disclaimer_en = "Reservation Terms"
        static let viewDisclaimer_zh = "查看预订须知"
        static let viewDisclaimer_en = "View Terms"
        static let disclaimerAccepted_zh = "已阅读预订须知"
        static let disclaimerAccepted_en = "Terms Accepted"
    }
    
    // MARK: - 验证配置
    struct Validation {
        static let minPartySize = 1
        static let maxPartySize = 12
        static let maxAdvanceBookingDays = 30
        static let minAdvanceBookingHours = 2
    }
    
    // MARK: - 业务逻辑配置
    struct Business {
        static let timeSlotIntervalMinutes = 30
        static let maxTimeSlots = 20
        static let defaultReservationDurationHours = 2
    }
}

// MARK: - 扩展方法
extension ReservationFlowConfig {
    
    /// 获取本地化字符串
    static func localizedString(_ key: String, language: String = "zh") -> String {
        // 这里可以根据实际需求实现更复杂的本地化逻辑
        return language == "zh" ? key : key
    }
    
    /// 获取主题颜色
    static func themeColor(for orderType: String) -> Color {
        switch orderType {
        case "immediately_dine_in":
            return Colors.primaryOrange
        case "immediately_takeaway":
            return Colors.primaryGreen
        case "reservation_dine_in":
            return Colors.primaryBlue
        case "reservation_takeaway":
            return Colors.primaryPurple
        default:
            return Colors.primaryOrange
        }
    }
    
    /// 创建渐变背景
    static func createGradientBackground(selected: Bool, color: Color = Colors.primaryOrange) -> some View {
        RoundedRectangle(cornerRadius: Layout.cardCornerRadius)
            .fill(
                selected ?
                LinearGradient(
                    colors: [color, color.opacity(0.7)],
                    startPoint: .topLeading,
                    endPoint: .bottomTrailing
                ) :
                LinearGradient(
                    colors: [Colors.backgroundPrimary, Colors.backgroundSecondary],
                    startPoint: .topLeading,
                    endPoint: .bottomTrailing
                )
            )
            .overlay(
                RoundedRectangle(cornerRadius: Layout.cardCornerRadius)
                    .stroke(
                        selected ? color.opacity(0.8) : Colors.borderPrimary,
                        lineWidth: selected ? 2 : 1
                    )
            )
    }
    
    /// 创建按钮样式
    static func createButtonStyle(enabled: Bool, color: Color = Colors.primaryOrange) -> some View {
        LinearGradient(
            colors: enabled ? [color, color.opacity(0.7)] : [Color.gray.opacity(0.5)],
            startPoint: .leading,
            endPoint: .trailing
        )
    }
}